<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
<#include "/WEB-INF/views/template/bootMainCss.ftl" parse=true encoding="utf-8">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <style>
        .name{ float: right;}
        .row{ margin: 0;}
        .shop-img{ text-align: left; padding-left: 30px;}
        .shop-img img{ margin-right: 10px;}
        .panel-body{ padding-bottom:15px; }
        #tbodyId{ font-size: 13px;}
        #myTable thead{ font-size: 14px;}
    </style>
</head>
<body>

<div class="panel panel-lzy">
    <div class="panel-body">
        <h5 class="tips-lzy">操作提示</h5>
        <ul class="tips-list-lzy">
            <li>◆&nbsp;<span>目前以订单量这一种方式设置条件。</span></li>
            <li>◆&nbsp;<span>开通下级功能是为了销售员在实际销售过程中达到后台所设置的要求时，前台提醒他可以成立团队招聘成员或者获得相应奖励。</span></li>
        </ul>
    </div>
</div>

<div class="panel panel-f5">
    <div class="panel-heading row">
        <button type="button" class="btn btn-primary" onclick="addMeal();"><span class="fa fa-plus"></span> 新增分类</button>
        <button type="button" class="btn btn-primary" onclick="batchDown();">批量移除</button>
    </div>
    <!-- 分页查询的地址-->
    <div class="panel-body panel-white">
        <div class="table-responsive">
            <table id="myTable"
                   class="table table-hover"
                   data-url="${basePath}/admin/product/level/json"
                   data-pageSize="10,50,100" data-method="GET">
                <thead>
                <!-- 需要循环的字段  对应mapper文件-->
                <tr>
                    <th  data-type="checkbox" data-field="id"></th>
                    <th  data-field="id">ID</th>
                    <th  data-field="conditionName" data-call="true">条件</th>
                    <th  data-field="createUserName" width="15%">新增人</th>
                    <th  data-field="createTime" data-call="true" width="25%">新增时间</th>
                    <th  data-field="classifyName" data-call="true">关联分类</th>
                    <th  data-field="button" data-call="true">操作</th>
                </tr>
                </thead>
                <tbody id="tbodyId">

                </tbody>
            </table>
        </div>
        <!-- 分页条-->
        <div class="row">
            <div align="left" class="col-xs-6">
                <div class="input-group">
                    <span class="input-group-addon" id="pageCount"></span> <select
                        id="pageSize" onchange="search(1)" class="form-control"
                        style="width: 100px"></select>
                </div>
            </div>
            <div align="right" class="col-xs-6">
                <ul class="pagination" id="pagination"></ul>
            </div>
        </div>
    </div>

</div>
<#include "/WEB-INF/views/template/bootMainJs.ftl" parse=true encoding="utf-8">
<script type="text/javascript" src="${basePath}/bootstrap/js/utils.js" type="text/javascript"></script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/jqPaginator/jqPaginator.js"></script>
<script type="text/javascript" src="${basePath}/bootstrap/plugin/jqPaginator/myPage.js"></script>
<script type="text/javascript">
    //循环列表数据以及操作按钮
    function tableCallBack(data, id){
        if(id == 'button') {//增加操作按钮
            var _button = '<button type="button" class="btn btn-white btn-xs" onclick="editMeal(' + data.id + ');">编辑 </button> ';
            _button += '<button type="button" class="btn btn-white btn-xs" onclick="downMarket(' + data.id + ');" >移除</button> ';
            return _button;
        }
        else if(id == "banner"){
            return "<div class='shop-img'><img src='"+data.banner+"' height='50'><span>"+data.name+"</span></div>";
        }
        else {
            if(data[id] == null || data[id] == ''){
                return '';
            }else{
                return data[id];
            }
        }
    }

    //详情
    function viewMeal(id){
        window.location.href='${basePath}/admin/product/level/view?id='+id;
    }

    //新增
    function addMeal(){
        window.location.href='${basePath}/admin/product/level/add';
    }

    //编辑
    function editMeal(id){
        window.location.href='${basePath}/admin/product/level/edit?id=' + id;
    }

    //单个移除
    function downMarket(id){
        layer.confirm('是否确定此操作？', {
            btn: ['确定','取消'] //按钮
        }, function() {
            $.ajax({
                type: 'GET',
                url: '${basePath}/admin/product/level/remove?id='+id,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.code == '0') {
                        layer.alert('移除成功!', {
                            icon: 6
                        }, function(index){
                            layer.closeAll('dialog');
                            search(parseInt($('.active').attr('jp-data')));
                        });
                    } else {
                        layer.alert(data.desc, {
                            icon: 56
                        });
                    }
                }
            });
        });
    }

    //批量移除
    function batchDown(){
        var chk_value =[];
        $("#tbodyId").find("input").each(function() {
            if($(this).attr('type') == 'checkbox' && $(this).is(':checked')){
                chk_value.push($(this).val());
            }
        });
        if(chk_value.join(",") == null || chk_value.join(",") == ''){
            layer.alert('请选择需要移除的内容', {icon : 5});
            return;
        }
        layer.confirm('是否确定此操作？', {
            btn: ['确定','取消'] //按钮
        }, function() {
            $.ajax({
                type: 'POST',
                url: '${basePath}/admin/product/level/removeList?ids='+chk_value,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.code == '0') {
                        layer.alert('批量移除成功!', {
                            icon: 6
                        }, function(index){
                            layer.closeAll('dialog');
                            search(parseInt($('.active').attr('jp-data')));
                        });
                    } else {
                        layer.alert(data.desc, {
                            icon: 56
                        });
                    }
                }
            });
        });
    }
</script>
</body>
</html>